package com.atguigu.gulimall.product.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration //配置类
@EnableSwagger2// 开启Swagger2的自动配置
@Slf4j
public class SwaggerConfig {
    /*@Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("A");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("B");
    }
    @Bean
    public Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("C");
    }*/



    @Bean
    public Docket docket(Environment environment){
        Profiles profiles = Profiles.of("dev","test");
        boolean b = environment.acceptsProfiles(profiles);
        log.info("b的值是="+b);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
               // .enable(b)
                .groupName("刘光辉")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.atguigu.gulimall.product.controller"))
                //.paths(PathSelectors.ant("/controller"))
                .build();
    }

    public ApiInfo apiInfo(){
        Contact contact = new Contact("刘光辉", "www.baidu.com", "1573804696@qq.com");
        return new ApiInfo(
                "刘光辉swaggerAPI文档",
                "在小的帆也能远航",
                "v1.0",
                "www.guge.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );

    }
}